package com.indusfo.spc.controller;


import com.indusfo.spc.aspect.SystemControllerLog;
import com.indusfo.spc.exception.GlobalException;
import com.indusfo.spc.pojo.ScrapWork;
import com.indusfo.spc.service.ScrapWorkService;
import com.indusfo.spc.vo.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 报废作业控制层
 */
@Controller
@RequestMapping("/service/scrapWork")
public class ScrapWorkController {

    @Autowired
    private ScrapWorkService scrapWorkService;

    /**
     * 查询
     * @return com.indusfo.spc.vo.JSONObject
     */
    @RequestMapping(value="/queryScrapWork")
    @SystemControllerLog(description="查询")
    @ResponseBody
    public JSONObject queryScrapWork(ScrapWork scrapWork,String startDate,String endDate) {
        JSONObject json = scrapWorkService.selectScrapWork(scrapWork,startDate,endDate);
        return json;
    }

    /**
     * 新增
     * @return com.indusfo.spc.vo.JSONObject
     */
    @RequestMapping(value="/insertScrapWork")
    @SystemControllerLog(description="新增")
    @ResponseBody
    public JSONObject insertScrapWork(ScrapWork scrapWork) {
        JSONObject json = scrapWorkService.insertScrapWork(scrapWork);
        return json;
    }

    /**
     * 修改
     * @return
     */
    @RequestMapping(value = "/updateScrapWork")
    @SystemControllerLog(description="修改")
    @ResponseBody
    public JSONObject updateScrapWork(ScrapWork scrapWork){
        JSONObject json=scrapWorkService.updateScrapWork(scrapWork);
        return json;
    }

    /**
     * 启用/停用
     * @return com.indusfo.spc.vo.JSONObject
     */
    @RequestMapping(value="/definedScrapWork")
    @SystemControllerLog(description="启用/停用")
    @ResponseBody
    public JSONObject definedScrapWork(Long[] scrapWorkIds,Integer[] auditStates, Integer dataState) {
        JSONObject json = scrapWorkService.definedScrapWork(scrapWorkIds,auditStates, dataState);
        return json;
    }

    /**
     * 删除
     * @return com.indusfo.spc.vo.JSONObject
     */
    @RequestMapping(value="/deleteScrapWork")
    @SystemControllerLog(description="删除")
    @ResponseBody
    public JSONObject deleteScrapWork(Long[] scrapWorkIds,Integer[] auditStates, Integer dataState) {
        dataState = 2;
        JSONObject json = scrapWorkService.definedScrapWork(scrapWorkIds,auditStates, dataState);
        return json;
    }

    /**
     * 审核/反审核
     * @return com.indusfo.spc.vo.JSONObject
     */
    @RequestMapping(value="/auditScrapWork")
    @SystemControllerLog(description="审核/反审核")
    @ResponseBody
    public JSONObject auditScrapWork(Long[] scrapWorkIds, Integer[] auditStates, Integer auditState, Integer auditUserId) {
        try{
            JSONObject json = scrapWorkService.auditScrapWork(scrapWorkIds, auditStates ,auditState ,auditUserId);
            return json;
        } catch ( GlobalException e) {
            e.printStackTrace();
            return JSONObject.build(403, e.getMessage());
        }
    }

}
